package com.soft.face.config.arcsoft;

import cn.hutool.extra.spring.SpringUtil;
import com.soft.face.entity.ArcSoft;
import com.soft.face.entity.UserFace;
import com.soft.face.service.ArcSoftService;
import com.soft.face.service.UserFaceService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Component
@Order(value = 2)
@AllArgsConstructor
public class ArcSoftFaceInit implements CommandLineRunner {

    private UserFaceService userFaceService;
    private ArcSoftService arcSoftService;

    @Override
    public void run(String... args) throws Exception {
        // 每次重启数据清理
        List<String> arcSoftIds = arcSoftService.list().stream().map(ArcSoft::getId).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(arcSoftIds)) {
            arcSoftService.removeByIds(arcSoftIds);
        }
        List<String> faceIds = userFaceService.list().stream().map(UserFace::getId).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(faceIds)) {
            userFaceService.removeByIds(faceIds);
        }
    }

}
